/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JServiceFilter.java
 *
 * Created on 2009-9-16, 10:20:21
 */

package cn.ekuma.epos.servings;

import cn.ekuma.epos.core.util.ProductSwingUtil;
import cn.ekuma.epos.datalogic.I_DataLogicCustomers;
import cn.ekuma.epos.datalogic.I_DataLogicSales;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.ComboBoxValEntry;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.query.QBF;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.serialize.serializer.SerializerWrite;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteBasic;
import com.openbravo.data.loader.query.QBFCompareEnum;
import com.openbravo.editor.JEditorKeys;

import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.base.AppView;
import com.openbravo.bean.Place;
import com.openbravo.bean.Product;
import com.openbravo.bean.Service;
import com.openbravo.bean.infobean.UserInfo;
import com.openbravo.pos.panels.JPlaceFinder;
import com.openbravo.pos.panels.JProductFinder;
import com.openbravo.pos.panels.JObjectListFinder;
import com.openbravo.pos.reports.ReportEditorCreator;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Toolkit;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class JServiceFilter extends javax.swing.JPanel implements ReportEditorCreator{
    private I_DataLogicSales m_dlSales;


    public  JServiceFilter(I_DataLogicSales m_dlSales) {
        this.m_dlSales=m_dlSales;
        initComponents();
        serviceTypeModel=new ComboBoxValModel();
        serviceTypeModel.add(new ComboBoxValEntry(Service.SERVICETYPE_product, AppLocal.getIntString("list.SERVICETYPE_product")));
        serviceTypeModel.add(new ComboBoxValEntry(Service.SERVICETYPE_place, AppLocal.getIntString("list.SERVICETYPE_place")));
        serviceTypeModel.add(new ComboBoxValEntry(Service.SERVICETYPE_user, AppLocal.getIntString("list.SERVICETYPE_user")));
        serviceTypeModel.add(ComboBoxValEntry.buildEntry_all());
        jServiceType.setModel(serviceTypeModel);
        jServiceType.setSelectedItem(ComboBoxValEntry.buildEntry_all());
    }

    private  ComboBoxValModel serviceTypeModel;
    private Product product;
    private UserInfo currentUser;
    private Place currentPlace;

    JServiceFilter(I_DataLogicSales dlSales, JEditorKeys m_jKeys) {
        this(dlSales);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jServiceId = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jServiceType = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        jServiceName = new javax.swing.JTextField();
        jCardPanel = new javax.swing.JPanel();
        jProductPanel = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jEditProduct = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        m_jEnter = new javax.swing.JButton();
        m_jreference = new javax.swing.JTextField();
        m_jEnter1 = new javax.swing.JButton();
        jproduct = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        m_jcodebar = new javax.swing.JTextField();
        jEditAttributes = new javax.swing.JButton();
        jattributes = new javax.swing.JTextField();
        jUserPanel = new javax.swing.JPanel();
        jcard = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        m_jName = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        m_jFindUserByName = new javax.swing.JButton();
        m_jFindUserByCard = new javax.swing.JButton();
        jUserList = new javax.swing.JButton();
        jPlacePanel = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        m_jName1 = new javax.swing.JTextField();
        JLabel4 = new javax.swing.JLabel();
        jm_sID = new javax.swing.JTextField();
        m_jFindPlaceById = new javax.swing.JButton();
        m_jFindPlaceByName = new javax.swing.JButton();
        jFindPlace = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(480, 210));
        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));

        jLabel1.setText(AppLocal.getIntString("label.sevice_ID")); // NOI18N

        jLabel2.setText(AppLocal.getIntString("label.sevice_Type")); // NOI18N

        jServiceType.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jServiceTypeItemStateChanged(evt);
            }
        });

        jLabel18.setText(AppLocal.getIntString("label.sevice_Name")); // NOI18N

        jServiceName.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jServiceId, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jServiceType, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jServiceName, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(82, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jServiceId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jServiceType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jServiceName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(jPanel1);

        jCardPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jCardPanel.setPreferredSize(new java.awt.Dimension(480, 104));
        jCardPanel.setLayout(new java.awt.CardLayout());

        jProductPanel.setMinimumSize(new java.awt.Dimension(470, 150));
        jProductPanel.setPreferredSize(new java.awt.Dimension(470, 150));

        jLabel6.setText(AppLocal.getIntString("label.stockproduct")); // NOI18N

        jLabel12.setText(AppLocal.getIntString("label.prodref")); // NOI18N

        jEditProduct.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/search.png"))); // NOI18N
        jEditProduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jEditProductActionPerformed(evt);
            }
        });

        jLabel11.setText(AppLocal.getIntString("label.attributes")); // NOI18N

        m_jEnter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jEnter.setFocusPainted(false);
        m_jEnter.setFocusable(false);
        m_jEnter.setRequestFocusEnabled(false);
        m_jEnter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jEnterActionPerformed(evt);
            }
        });

        m_jreference.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jreferenceActionPerformed(evt);
            }
        });

        m_jEnter1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jEnter1.setFocusPainted(false);
        m_jEnter1.setFocusable(false);
        m_jEnter1.setRequestFocusEnabled(false);
        m_jEnter1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jEnter1ActionPerformed(evt);
            }
        });

        jproduct.setEditable(false);

        jLabel7.setText(AppLocal.getIntString("label.prodbarcode")); // NOI18N

        m_jcodebar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jcodebarActionPerformed(evt);
            }
        });

        jEditAttributes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/colorize16.png"))); // NOI18N
        jEditAttributes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jEditAttributesActionPerformed(evt);
            }
        });

        jattributes.setEditable(false);

        javax.swing.GroupLayout jProductPanelLayout = new javax.swing.GroupLayout(jProductPanel);
        jProductPanel.setLayout(jProductPanelLayout);
        jProductPanelLayout.setHorizontalGroup(
            jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jProductPanelLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jProductPanelLayout.createSequentialGroup()
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jattributes, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jproduct, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jProductPanelLayout.createSequentialGroup()
                        .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jProductPanelLayout.createSequentialGroup()
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(m_jreference, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jProductPanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(m_jcodebar, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(14, 14, 14)
                .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jEditAttributes, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jEditProduct, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(m_jEnter, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(m_jEnter1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29))
            .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jProductPanelLayout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(335, Short.MAX_VALUE)))
        );
        jProductPanelLayout.setVerticalGroup(
            jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jProductPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel12)
                    .addComponent(m_jreference)
                    .addComponent(m_jEnter1, 0, 0, Short.MAX_VALUE))
                .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jProductPanelLayout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(m_jEnter, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jProductPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(m_jcodebar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jProductPanelLayout.createSequentialGroup()
                        .addComponent(jEditProduct, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jEditAttributes))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jProductPanelLayout.createSequentialGroup()
                        .addComponent(jproduct, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jattributes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(29, Short.MAX_VALUE))
            .addGroup(jProductPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jProductPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel6)
                    .addContainerGap(124, Short.MAX_VALUE)))
        );

        jCardPanel.add(jProductPanel, "product");

        jUserPanel.setPreferredSize(new java.awt.Dimension(476, 150));

        jLabel5.setText(AppLocal.getIntString("label.peoplename")); // NOI18N

        jLabel8.setText(AppLocal.getIntString("label.card")); // NOI18N

        m_jFindUserByName.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jFindUserByName.setFocusPainted(false);
        m_jFindUserByName.setFocusable(false);
        m_jFindUserByName.setRequestFocusEnabled(false);
        m_jFindUserByName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jFindUserByNameActionPerformed(evt);
            }
        });

        m_jFindUserByCard.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jFindUserByCard.setFocusPainted(false);
        m_jFindUserByCard.setFocusable(false);
        m_jFindUserByCard.setRequestFocusEnabled(false);
        m_jFindUserByCard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jFindUserByCardActionPerformed(evt);
            }
        });

        jUserList.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/search.png"))); // NOI18N
        jUserList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jUserListActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jUserPanelLayout = new javax.swing.GroupLayout(jUserPanel);
        jUserPanel.setLayout(jUserPanelLayout);
        jUserPanelLayout.setHorizontalGroup(
            jUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jUserPanelLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(jUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jUserPanelLayout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(m_jFindUserByName, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jUserPanelLayout.createSequentialGroup()
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcard, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(m_jFindUserByCard, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jUserList)
                .addContainerGap(65, Short.MAX_VALUE))
        );
        jUserPanelLayout.setVerticalGroup(
            jUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jUserPanelLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jUserList, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
                    .addGroup(jUserPanelLayout.createSequentialGroup()
                        .addGroup(jUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(m_jFindUserByName))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jUserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jLabel8)
                            .addComponent(jcard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(m_jFindUserByCard))))
                .addGap(61, 61, 61))
        );

        jCardPanel.add(jUserPanel, "user");

        jPlacePanel.setPreferredSize(new java.awt.Dimension(476, 150));

        jLabel9.setText(AppLocal.getIntString("Label.Name")); // NOI18N

        JLabel4.setText("ID");

        jm_sID.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        m_jFindPlaceById.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jFindPlaceById.setFocusPainted(false);
        m_jFindPlaceById.setFocusable(false);
        m_jFindPlaceById.setRequestFocusEnabled(false);
        m_jFindPlaceById.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jFindPlaceByIdActionPerformed(evt);
            }
        });

        m_jFindPlaceByName.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/apply.png"))); // NOI18N
        m_jFindPlaceByName.setFocusPainted(false);
        m_jFindPlaceByName.setFocusable(false);
        m_jFindPlaceByName.setRequestFocusEnabled(false);
        m_jFindPlaceByName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jFindPlaceByNameActionPerformed(evt);
            }
        });

        jFindPlace.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/search.png"))); // NOI18N
        jFindPlace.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFindPlaceActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPlacePanelLayout = new javax.swing.GroupLayout(jPlacePanel);
        jPlacePanel.setLayout(jPlacePanelLayout);
        jPlacePanelLayout.setHorizontalGroup(
            jPlacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPlacePanelLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(jPlacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPlacePanelLayout.createSequentialGroup()
                        .addComponent(JLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jm_sID))
                    .addGroup(jPlacePanelLayout.createSequentialGroup()
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(m_jName1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPlacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(m_jFindPlaceById, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(m_jFindPlaceByName, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addComponent(jFindPlace)
                .addContainerGap(54, Short.MAX_VALUE))
        );
        jPlacePanelLayout.setVerticalGroup(
            jPlacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPlacePanelLayout.createSequentialGroup()
                .addGroup(jPlacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPlacePanelLayout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(jFindPlace, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPlacePanelLayout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addGroup(jPlacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(m_jFindPlaceById)
                            .addGroup(jPlacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jm_sID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(JLabel4)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPlacePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9)
                            .addComponent(m_jName1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(m_jFindPlaceByName))))
                .addContainerGap(60, Short.MAX_VALUE))
        );

        jCardPanel.add(jPlacePanel, "place");

        add(jCardPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void jServiceTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jServiceTypeItemStateChanged
        changeServiceType();
}//GEN-LAST:event_jServiceTypeItemStateChanged

    private void jEditProductActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jEditProductActionPerformed

        assignProduct(JProductFinder.showMessage(this, m_dlSales));
}//GEN-LAST:event_jEditProductActionPerformed

    private void m_jEnterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jEnterActionPerformed

        assignProductByCode();
}//GEN-LAST:event_m_jEnterActionPerformed

    private void m_jreferenceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jreferenceActionPerformed

        assignProductByReference();
}//GEN-LAST:event_m_jreferenceActionPerformed

    private void m_jEnter1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jEnter1ActionPerformed

        assignProductByReference();
}//GEN-LAST:event_m_jEnter1ActionPerformed

    private void m_jcodebarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jcodebarActionPerformed

        assignProductByCode();
}//GEN-LAST:event_m_jcodebarActionPerformed

    private void jEditAttributesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jEditAttributesActionPerformed
        /**
         * if (productid == null) {
         * // first select the product.
         * MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.productnotselected"));
         * msg.show(this);
         * } else {
         * try {
         * JProductAttEdit attedit = JProductAttEdit.getAttributesEditor(this, m_App.getSession());
         * attedit.editAttributes(attsetid, attsetinstid);
         * attedit.setVisible(true);
         *
         * if (attedit.isOK()) {
         * // The user pressed OK
         * attsetinstid = attedit.getAttributeSetInst();
         * attsetinstdesc = attedit.getAttributeSetInstDescription();
         * jattributes.setText(attsetinstdesc);
         * }
         * } catch (BasicException ex) {
         * MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotfindattributes"), ex);
         * msg.show(this);
         * }
         * }
         * */
}//GEN-LAST:event_jEditAttributesActionPerformed

    private void m_jFindUserByNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jFindUserByNameActionPerformed
        assignUserByName();
}//GEN-LAST:event_m_jFindUserByNameActionPerformed

    private void m_jFindUserByCardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jFindUserByCardActionPerformed
        assignUserByCard();
}//GEN-LAST:event_m_jFindUserByCardActionPerformed

    private void jUserListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jUserListActionPerformed
        try {
            List allUser = m_dlSales.listPeopleVisible();
            JObjectListFinder userList = JObjectListFinder.newJDialog(this);
            UserInfo tempUser = (UserInfo)userList.showUserList(allUser);
            assignUser(tempUser);
        } catch (BasicException ex) {
            MessageInf msg = new MessageInf(ex);
            msg.show(this);
            assignUser(null);
        }
        // assignProduct(JProductFinder.showMessage(this, m_dlSales));
}//GEN-LAST:event_jUserListActionPerformed

    private void m_jFindPlaceByIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jFindPlaceByIdActionPerformed
        assignPlaceById();
}//GEN-LAST:event_m_jFindPlaceByIdActionPerformed

    private void m_jFindPlaceByNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jFindPlaceByNameActionPerformed
        assignPlaceByName();
}//GEN-LAST:event_m_jFindPlaceByNameActionPerformed

    private void jFindPlaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFindPlaceActionPerformed
        assignPlace(JPlaceFinder.showMessage(this, m_dlSales));
}//GEN-LAST:event_jFindPlaceActionPerformed


    @Override
    public void activate() {
       product=null;
       currentUser=null;
       currentPlace=null;
    }

    @Override
    public Component getComponent() {
        return this;
    }

    @Override
    public SerializerWrite getSerializerWrite() {
       return new SerializerWriteBasic(Datas.OBJECT, Datas.STRING,Datas.OBJECT, Datas.STRING);
    }

    @Override
    public Object createValue() throws BasicException {
        ComboBoxValEntry selectedEntry=(ComboBoxValEntry) jServiceType.getSelectedItem();
        String refId=null;
        if (Service.SERVICETYPE_user.equalsIgnoreCase((String) selectedEntry.getM_sKey())) {//用户类
               if(this.currentUser!=null){
                   refId=currentUser.getId();
               }
            } else if (Service.SERVICETYPE_place.equalsIgnoreCase((String) selectedEntry.getM_sKey())) { //资源类
                if(this.currentPlace!=null){
                   refId=currentPlace.getId();
               }
            } else if (Service.SERVICETYPE_product.equalsIgnoreCase((String) selectedEntry.getM_sKey())) {//产品类
               if(this.product!=null){
                  refId=product.getID();
             }
        }

        String serviceId=this.jServiceId.getText();
        if(serviceId==null||serviceId.isEmpty()){
            if(refId!=null){
               /** return new Object[]{
                        QBFCompareEnum.COMP_NONE, null,
                        QBFCompareEnum.COMP_EQUALS, selectedEntry.getM_sKey(),
                        QBFCompareEnum.COMP_EQUALS, refId
                         };**/
               return QBF.c().eq(fields[1],selectedEntry.getM_sKey()).eq(fields[2],refId).build();
            }
        }else{
                /*return new Object[]{
                        QBFCompareEnum.COMP_EQUALS, serviceId,
                        QBFCompareEnum.COMP_NONE, null,
                        QBFCompareEnum.COMP_NONE, null
                         };*/
            return QBF.c().eq(fields[0],serviceId).build();
        }

      /* return  new Object[]{
            QBFCompareEnum.COMP_NONE, null,
            QBFCompareEnum.COMP_NONE, null,
            QBFCompareEnum.COMP_NONE, null
        };*/
      return QBF.c(true).build();

    }

     String[] fields=new String[]{"ID", "SERVICETYPE", "REF_ID"};

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel JLabel4;
    private javax.swing.JPanel jCardPanel;
    private javax.swing.JButton jEditAttributes;
    private javax.swing.JButton jEditProduct;
    private javax.swing.JButton jFindPlace;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPlacePanel;
    private javax.swing.JPanel jProductPanel;
    private javax.swing.JTextField jServiceId;
    private javax.swing.JTextField jServiceName;
    private javax.swing.JComboBox jServiceType;
    private javax.swing.JButton jUserList;
    private javax.swing.JPanel jUserPanel;
    private javax.swing.JTextField jattributes;
    private javax.swing.JTextField jcard;
    private javax.swing.JTextField jm_sID;
    private javax.swing.JTextField jproduct;
    private javax.swing.JButton m_jEnter;
    private javax.swing.JButton m_jEnter1;
    private javax.swing.JButton m_jFindPlaceById;
    private javax.swing.JButton m_jFindPlaceByName;
    private javax.swing.JButton m_jFindUserByCard;
    private javax.swing.JButton m_jFindUserByName;
    private javax.swing.JTextField m_jName;
    private javax.swing.JTextField m_jName1;
    private javax.swing.JTextField m_jcodebar;
    private javax.swing.JTextField m_jreference;
    // End of variables declaration//GEN-END:variables


      private void assignProductByReference() {
        try {
            Product prod = m_dlSales.getProductInfoByReference(m_jreference.getText());
            if (prod == null) {
                Toolkit.getDefaultToolkit().beep();
            }
            assignProduct(prod);

        } catch (BasicException eData) {
            MessageInf msg = new MessageInf(eData);
            msg.show(this);
            assignProduct(null);
        }
    }

    private void assignProductByCode() {
            Product prod =ProductSwingUtil.getProductInfo(this, m_dlSales, m_jcodebar.getText());
            if (prod == null) {
                Toolkit.getDefaultToolkit().beep();
            }
            assignProduct(prod);
    }

    private void assignProduct(Product prod) {
        product = prod;
        if(product!=null){
           setServiceName(product.getName());
        }else{
           setServiceName(null);
        }
        printProudct();
    }

    private void printProudct(){
         if (product == null) {
            jproduct.setText(null);
            m_jcodebar.setText(null);
            m_jreference.setText(null);
        } else {
            jproduct.setText(product.getReference() + " - " + product.getName());
            m_jcodebar.setText(product.getCode());
            m_jreference.setText(product.getReference());
        }
    }

    private void assignUserByName() {
        try {
            UserInfo prod = m_dlSales.findPeopleByName(m_jName.getText());
            if (prod == null) {
                Toolkit.getDefaultToolkit().beep();
            }
            assignUser(prod);
        } catch (BasicException eData) {
            MessageInf msg = new MessageInf(eData);
            msg.show(this);
            assignUser(null);
        }
    }

    private void assignUserByCard() {
        try {
            UserInfo prod = m_dlSales.findPeopleByCard(jcard.getText());
            if (prod == null) {
                Toolkit.getDefaultToolkit().beep();
            }
            assignUser(prod);
        } catch (BasicException eData) {
            MessageInf msg = new MessageInf(eData);
            msg.show(this);
            assignUser(null);
        }
    }

    private void assignUser(UserInfo user) {
        this.currentUser = user;
          if(currentUser!=null){
           setServiceName(user.getName());
        }else{
           setServiceName(null);  
        }
         printUser();
    }

    private void printUser(){
         if (currentUser != null) {
            m_jName.setText(currentUser.getName());
            jcard.setText(currentUser.getId());
        } else {
            m_jName.setText(null);
            jcard.setText(null);
        }
    }

    private void assignPlaceById() {
        try {
            Place prod = (Place) m_dlSales.findByStringId(Place.class,jm_sID.getText());
            if (prod == null) {
                Toolkit.getDefaultToolkit().beep();
            }
            assignPlace(prod);
        } catch (BasicException eData) {
            MessageInf msg = new MessageInf(eData);
            msg.show(this);
            assignPlace(null);
        }
    }

    private void assignPlaceByName() {
        try {
            Place prod = m_dlSales.findPlaceByName(m_jName1.getText());
            if (prod == null) {
                Toolkit.getDefaultToolkit().beep();
            }
            assignPlace(prod);
        } catch (BasicException eData) {
            MessageInf msg = new MessageInf(eData);
            msg.show(this);
            assignPlace(null);
        }
    }

    private void assignPlace(Place place) {
        this.currentPlace = place;
         if(currentPlace!=null){
           setServiceName(place.getName());
        }else{
           setServiceName(null);
        }
        printPlace();
    }

    private void printPlace(){
        if (currentPlace != null) {
            jm_sID.setText(currentPlace.getId());
            m_jName1.setText(currentPlace.getName());
        } else {
            jm_sID.setText(null);
            m_jName1.setText(null);
        }
    }

    private void showCard(String cardName) {
        CardLayout cardLayout = (CardLayout) jCardPanel.getLayout();
        cardLayout.show(jCardPanel, cardName);
    }

    private void changeServiceType() {
        ComboBoxValEntry selectedEntry=(ComboBoxValEntry) jServiceType.getSelectedItem();
        String selViewName=null;
         if (Service.SERVICETYPE_user.equalsIgnoreCase((String) selectedEntry.getM_sKey())) {//用户类
               selViewName="user";
               if(this.currentUser!=null){
                   this.setServiceName(currentUser.getName());
               }
            } else if (Service.SERVICETYPE_place.equalsIgnoreCase((String) selectedEntry.getM_sKey())) { //资源类
                selViewName="place";
                if(this.currentPlace!=null){
                   this.setServiceName(currentPlace.getName());
               }
            } else if (Service.SERVICETYPE_product.equalsIgnoreCase((String) selectedEntry.getM_sKey())) {//产品类
               selViewName="product";
               if(this.product!=null){
                   this.setServiceName(product.getName());
             }
          }
        showCard(selViewName);
    }

     private void setServiceName(String name) {
        jServiceName.setText(name);
    }
}
